package com.jasonzqshen.ifm.utils;

import org.eclipse.core.runtime.Status;

import com.jasonzqshen.ifm.Plugin;

/**
 * System running log
 * 
 * @author Jason
 * 
 */
public class SystemLog {
    /**
     * Cannot constructor the class
     */
    private SystemLog() {
    }

    /**
     * Log msg
     * 
     * @param severity
     *            The severity, one of OK, ERROR, INFO, WARNING or CANCEL
     * @param code
     *            The plug-in special status code or OK.
     * @param msg
     *            Message
     * @param e
     *            a low level exception or null
     */
    public static void log(int severity, int code, String msg, Throwable e) {
        Plugin plugin = Plugin.getDefault();
        Status status = new Status(severity, Plugin.PLUGIN_ID, code, msg, e);
        plugin.getLog().log(status);
    }

    /**
     * Log Information
     * 
     * @param info
     */
    public static void logInfo(String info) {
        log(Status.INFO, 0, info, null);
    }

    /**
     * Log warning message
     * 
     * @param warning
     */
    public static void logWarning(String warning) {
        logWarning(warning, null);
    }

    /**
     * Log Warning Message
     * 
     * @param warning
     * @param e
     */
    public static void logWarning(String warning, Throwable e) {
        StringBuilder msg = new StringBuilder("Warning: ").append(warning);
        log(Status.WARNING, Status.WARNING, msg.toString(), e);
    }

    public static void logError(String error, Throwable e) {
        StringBuilder msg = new StringBuilder("Error: ").append(error);
        log(Status.ERROR, Status.ERROR, msg.toString(), e);
    }
}
